<?php

/**
 * ghv actions.
 *
 * @package    sf_sandbox
 * @subpackage ghv
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class ghvActions extends sfActions
{
  /**
   * Executes index action
   *
   */
  public function executeIndex()
  {
    $this->forward('ghv', 'home');
  }
  public function executeSearch(){
  	$this->user = $this->getRequest()->getParameter('name');
  	$c = new Criteria;
    $c1 = $c->getNewCriterion(UserPeer::ID, $this->user);
	$c2 = $c->getNewCriterion(UserPeer::PHONE, $this->user);
	$c1->addOr($c2);
	$c->add($c1);
    $this->result = UserPeer::doSelect($c);
  
  }
  
  public function executeAdd2list(){
  	$this->id = $this->getRequest()->getParameter('id');
  	$c = new Criteria();
  	$c->add(GhvMemberPeer::USER_ID, $this->id);
  	$count = GhvMemberPeer::doCount($c);
	if(empty($count) || $count < 1){
	  	$member = new GhvMember();
	  	$member->setUserId($this->id);
	  	$member->setNew(true);
	  	$member->save();
  	}
  	
  	$this->listuser = GhvMember::getlist();
  }
  
  public function executeDelrecord(){
  	$this->id = $this->getRequest()->getParameter('id');
  	$member = GhvMemberPeer::retrieveByPK($this->id);
  	$member->delete();
  	$this->listuser = GhvMember::getlist();
  	
  }
}
